package org.edu.dao.impl;

import java.util.List;

import org.edu.dao.RolesDao;
import org.edu.model.Roles;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;

@Scope
@Repository
public class RolesDaoImpl implements RolesDao {

	@Autowired
	private SessionFactory sessionFactory;
	
	public RolesDaoImpl() {
	}

	@Override
	public void update(Roles roles) throws Exception {
		sessionFactory.getCurrentSession().update(roles);
	}

	@Override
	public List<Roles> roles() {
		return sessionFactory.getCurrentSession().createQuery("from Roles").list();
	}

	@Override
	public Roles findById(Long roles_id) throws Exception {
		return (Roles) sessionFactory.getCurrentSession().load(Roles.class, roles_id);
	}

}
